#ifndef WIDGETMOVIMIENTO_H_
#define WIDGETMOVIMIENTO_H_

#include <stdio.h>
#include <list>
#include <iostream>

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

#include "Parcel.h"
#include "Event.h"
#include "Widget.h"

#define WIDGET_DEFAULT_DAMAGE 10
#define WIDGET_DEFAULT_ANGLE 0

enum borderType {TOP_BORDER, BOTTOM_BORDER, RIGHT_BORDER, LEFT_BORDER};

class WidgetMovimiento: public Widget {

private:
	int damage;
	playElement type;

	bool checkProjectedCollision(WidgetMovimiento* widgetMov);
    bool checkColisionByPixel(SDL_Rect collisionRect, SDL_Surface *surfaceAux, SDL_Rect normalA, SDL_Surface *surfaceWithAux, SDL_Rect normalB);
    void initWidgetMovimiento(playElement type, int damage, int posX, int posY, int angle = WIDGET_DEFAULT_ANGLE);

protected:
	SDL_Surface* surfaceShown;
	int angle;
	int nextAngle;
	int nextX;
	int nextY;
	bool drawable;

	void prepareSurfaceShown();
	void positionCorrection();
	int analyseBorderIntersection(borderType border, SDL_Rect objectRect, SDL_Rect screenRect);
	SDL_Rect getNextRectangle();
    SDL_Rect NormalizeBounds(SDL_Rect rect);

public:
	WidgetMovimiento(playElement type,int posX, int posY,std::string imagePath, Widget* parent,int damage = WIDGET_DEFAULT_DAMAGE);
	WidgetMovimiento(playElement type,int posX, int posY,int angle, std::string imagePath, Widget *parent, int damage);
	WidgetMovimiento(playElement type,int posX, int posY,int ancho, int alto,std::string imagePath, Widget* parent,int damage = WIDGET_DEFAULT_DAMAGE);

	virtual ~WidgetMovimiento();
	virtual void showOn(SDL_Surface* canvasSurface);
	virtual void handleColision(WidgetMovimiento* with) = 0;
	void resolve();

	bool isDrawable();
	bool checkCollision(WidgetMovimiento* widgetMov);
	bool checkBasicCollision(WidgetMovimiento* widgetMov);
    int getDamage() const;

    playElement getType() const;

    void initColorKey();
    int getAngle() const;
    SDL_Rect getRectangle();

    void updateNextPosition(int nextX,int nextY);
    void updateNextAngle(int nextAngle);
};

#endif /* WIDGETMOVIMIENTO_H_ */
